package com.xy.annotaion.handler.kotlin.compiler.demo1

import com.xy.annotaion.handler.kotlin.p


fun words(str: String): List<String> {

    //set EOF = '\n'
    //if not , words will not correct and
    //word of the end will miss.
    val ss = str + '\n'

    val words = mutableListOf<String>()
    //str to chars
//    val chars = ss.toCharArray()
    var word = StringBuilder()

    for (c in ss) {
        if (c in listOf(' ', ',', ':', ';', '.', '\r', '\n')) {
            if (word.isNotBlank()) {
                words.add(word.toString())
                word.clear()
            }
            continue
        }
        word.append(c);
    }


    return words
}


fun main() {

    var code = """
        var a = 10 / 3
        var b = (5 + 3) * 2
        var c = a / b
    """.trimIndent()
    p(words(code))

    code = """
        fun words(str:String): List<String> {
            val words = mutableListOf<String>()

            val chars = str.toCharArray()
            var word = StringBuilder()

            for (c in chars){
                if(c == ' '){
                    if(word.isNotBlank()){
                        words.add(word.toString())
                        word.clear()
                    }
                    continue;
                }
                word.append(c);
            }


            return words;
        }
    """.trimIndent()

    p(words(code))

    var article = """
        The Definitive Java Programming Guide Fully updated for Java SE 8, 
        Java: The Complete Reference, Ninth Edition explains 
        how to develop, compile, debug, and run Java programs. 
        Bestselling programming author Herb Schildt covers the entire Java language, 
        including its syntax, keywords, and fundamental programming principles, 
        as well as significant portions of the Java API library. 
        JavaBeans, servlets, applets, and Swing are examined and real-world examples demonstrate Java in action. 
        New Java SE 8 features such as lambda expressions, the stream library, 
        and the default interface method are discussed in detail. 
        This Oracle Press resource also offers a solid introduction to JavaFX. 
        Coverage includes: Data types, variables, arrays, and operators Control statements Classes, 
        objects, and methods Method overloading and overriding Inheritance Interfaces and packages 
        Exception handling Multithreaded programming Enumerations, autoboxing, 
        and annotations The I/O classes Generics Lambda expressions String handling 
        The Collections Framework Networking Event handling AWT and Swing The Concurrent API 
        The Stream API Regular expressions JavaFX JavaBeans Applets and servlets Much, 
        much more ...
    """.trimIndent()

    p(words(article))
}
